/**
  ******************************************************************************
  * @file    sensor_service.h 
  * @author  CL
  * @version V1.0.0
  * @date    04-July-2014
  * @brief   
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
  *
  * Redistribution and use in source and binary forms, with or without modification,
  * are permitted provided that the following conditions are met:
  *   1. Redistributions of source code must retain the above copyright notice,
  *      this list of conditions and the following disclaimer.
  *   2. Redistributions in binary form must reproduce the above copyright notice,
  *      this list of conditions and the following disclaimer in the documentation
  *      and/or other materials provided with the distribution.
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
  *      may be used to endorse or promote products derived from this software
  *      without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
  ******************************************************************************
  */
  
/* Define to prevent recursive inclusion -------------------------------------*/  
#ifndef _SENSOR_SERVICE_H_
#define _SENSOR_SERVICE_H_

#ifdef __cplusplus
 extern "C" {
#endif 

/* Includes ------------------------------------------------------------------*/
#include "stm32l0xx_hal.h"
#include "hal_types.h"
#include "bluenrg_gatt_server.h"
#include "bluenrg_gap.h"
#include "string.h"
#include "bluenrg_gap_aci.h"
#include "bluenrg_gatt_aci.h"
#include "hci_const.h"
#include "gp_timer.h"
#include "bluenrg_hal_aci.h"
#include "bluenrg_aci_const.h"   
#include "hci.h"
#include "hal.h"
#include "sm.h"
#include "debug.h"
#include "compiler.h"
  
#include <stdlib.h>

/** @addtogroup X-CUBE-BLE1_Applications
 *  @{
 */

/** @addtogroup SensorDemo
 *  @{
 */
 
/** @addtogroup SENSOR_SERVICE 
 * @{
 */

/** @addtogroup SENSOR_SERVICE_Exported_Defines 
 * @{
 */
 
 #define BYTE_16_To_8(x) (x >> 8) , (x & 0xff)
/* Exported defines ----------------------------------------------------------*/   
#define IDB04A1 0
#define IDB05A1 1

typedef struct _ble_app_update_adv_t{
    uint8_t adv_len;
    uint8_t adv_value[4];
}ble_app_update_adv_t;

typedef __packed struct _ble_eeprom_data_t{
  uint16_t adv_interval;
  uint16_t adv_widnow;
  uint32_t adv_period;
}ble_eeprom_data_t;

/**
 * @}
 */
/*private function*************************************************************************/
/*BlueNRG init*/
void bluenrg_io_init(void);
void bluenrg_start_work(void);
void bluenrg_update_adv(void* data);
tBleStatus bluenrg_init(uint8_t* bdaddr);
tBleStatus bluenrg_delete_adv_type(uint8_t data);
void bluenrg_stop_adv(void);
#ifdef MANUFACTURE_ADV
tBleStatus bluenrg_adv_manufacture_data(uint8_t* data, uint8_t len);
#endif
/** @addtogroup SENSOR_SERVICE_Exported_Functions
 *  @{
 */

void setConnectable(void);
void GAP_ConnectionComplete_CB(uint8_t addr[6], uint16_t handle);
void GAP_DisconnectionComplete_CB(void);
void HCI_Event_CB(void *pckt);
void Attribute_Modified_CB(uint16_t handle, uint8_t data_length, uint8_t *att_data);
  
/**
 * @}OTA service
 */
tBleStatus bluenrg_add_firmware_check_service(void);
tBleStatus bluenrg_add_file_transmission_service(void);
tBleStatus bluenrg_add_ota_reset_manager_service(void);
tBleStatus bluenrg_add_crc_service(void);
/**
 * @}IP Service
 */
tBleStatus bluenrg_add_ip_rx_tx_service(void);
/**
 * @}
 */
void ble_update_char_value_callback(uint8_t status);
/**
 * @}
 */

void ble_begin(void);
void ble_standby(void);

void bluenrg_get_config_info(ble_eeprom_data_t* param_data);
#ifdef __cplusplus
}
#endif

#endif /* _SENSOR_SERVICE_H_ */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

